package org.spring.boot.rabbitmq.conf;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author: eastcom
 * @desc: MQ配置类
 **/
@Configuration
public class RabbitMqConfig {

	private RabbitExchangeConfig exchange;

	private RabbitQueueConfig queue;

	/**
	 * 当参数必填和位置固定，优先使用构造方法注入
	 * @param exchange 交换机管理器
	 * @param queue 队列管理器
	 */
	public RabbitMqConfig(RabbitExchangeConfig exchange, RabbitQueueConfig queue) {
		this.exchange = exchange;
		this.queue = queue;
	}

	//@Bean(name="bindingWlanToDirectExchange")
	public Binding bindingWlanToDirectExchange(){
		return BindingBuilder.bind(queue.wlanQueue()).to(exchange.directExchange()).with("*");
	}

	/**
	 * gnms消息队列绑定到topic上
	 * @return Binding
	 */
	//@Bean(name="bindingGnmsToTopicExchange")
	public Binding bindingGnmsToTopicExchange() {
		return BindingBuilder.bind(queue.gnmsQueue()).to(exchange.topicExchange())
				.with("gnms.*");
	}

	/**
	 * sms短信消息绑定到topic上
	 * @return Binding
	 */
	//@Bean(name = "bindingSmsToTopicExchange")
	public Binding bindingSmsToTopicExchange() {
		return BindingBuilder.bind(queue.smsQueue()).to(exchange.topicExchange())
				.with("sms.*");
	}

	/**
	 * 将Gnms消息绑定到广播模式上
	 * @return Binding
	 */
	@Bean(name = "bindingGnmsToFanoutExchange")
	public Binding bindingGnmsToFanoutExchange(){
		return BindingBuilder.bind(queue.gnmsQueue()).to(exchange.fanoutExchange());
	}

	/**
	 * 将SMS消息绑定到广播模式上
	 * @return Binding
	 */
	@Bean(name = "bindingSmsToFanoutExchange")
	public Binding bindingSmsToFanoutExchange(){
		return BindingBuilder.bind(queue.smsQueue()).to(exchange.fanoutExchange());
	}

	/**
	 * 将WLAN消息绑定到广播模式上
	 * @return Binding
	 */
	@Bean(name = "bindingWlanToFanoutExchange")
	public Binding bindingWlanToFanoutExchange(){
		return BindingBuilder.bind(queue.wlanQueue()).to(exchange.fanoutExchange());
	}
}
